package org.keyintegrity.webbeans.metadata.store;

import java.util.HashMap;
import java.util.Map;

public abstract class MetadataStoreFactory {
    
    private static final Map<MetadataStoreContext, MetadataStore> instances = 
        new HashMap<MetadataStoreContext, MetadataStore>();
    
    public static MetadataStore getMetadataStore(MetadataStoreContext context) {
        if (context == null) {
            throw new NullPointerException("context is null");
        }
        return getInstance(context);
    }
    
    private synchronized static MetadataStore getInstance(MetadataStoreContext context) {
        if (instances.get(context) == null) {
            instances.put(context, context.newMetadataStore()); 
        }
        return instances.get(context);
    }

}
